<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
</head>
<body>
<span id="str"></span>
<input type="button" value="我是同步任务" onclick="handle()" id="btn">
<script>
    let date = new Date();
    date.setMinutes(41);
    date.setSeconds(0);
    let timeStamp = date.getTime();

    function timeDown(date) {
        let currentStamp = new Date().getTime();
        let diff = date - currentStamp;
        let time = diff / 1000;
        let oStr = document.getElementById('str');
        timer = setInterval(() => {
            time--
            oStr.innerText = time;
            if (time === 0) {
                oStr.innerText = "倒计时已完成";
                clearInterval(timer);
                timer = null;
            }
        }, 1000)
    }

    function handle() {
        for (let i = 0; i < 10000; i++) {
            console.log(i);
            console.table(i);
        }
    }

    timeDown(timeStamp);

    // worker 解决方案
    let worker = new Worker('./js/worker.js');
</script>
</body>
</html>